#include <stdlib.h>
#include <string.h>
#include "time.h"
#include "game.h"
#include "account.h"

int main()
{
    srand((unsigned)time(NULL));
    int i=0;
    int function = 6;
    char name[21];
    int nameYNChange=0;
    while (function!=0) {
        printf("请选择功能:\n0.退出\n1.注册\n2.登陆\n3.修改\n4.注销\n5.play\n");
        scanf("%d", &function);

        
        switch (function)
        {
        case -1:
                for (int i=0; i<=100 ;i++) {
                    //printf("%d\n",(unsigned)time( NULL ));
                    printf("%d\n",rand()%100);
                }
                break;
        case 1:
                zhuce();
            break;
        case 2:
            {
               AccountNode *a=denglu();
                if (a==NULL) {
                    break;
                }
                strcpy(name, a->data.name);
                nameYNChange=1;
                AccountNode *h = loadAccount();
                i=a->data.winsNumber;
                if (playGuessNumderARound()>0) {
                    i++;
                }
                else
                {
                    i=0;
                }
                printf("您连胜了%d局.\n",i);
                a->data.winsNumber=i;
                modifyAccount(a->data.name, a, h);
                saveAccount(h);
            }
            break;
        case 3:
            modifySomeAccount();
            break;
        case 4:
            deleteSomeAccount();
            break;
        case 5:
            {
                i=0;
                AccountNode *h = loadAccount();
                AccountNode *a=findPreaccount(name, h);
                i=a->next->data.winsNumber;
                if (playGuessNumderARound()>0) {
                    i++;
                }
                else
                {
                    i=0;
                }
                printf("您连胜了%d局.\n",i);
                if (nameYNChange==0) {
                    break;
                }
                a->next->data.winsNumber=i;
                saveAccount(h);
            }
            break;
        default:
            break;
        }
    }
        
    
}

